package com.yunxi.service.dubboService.impl.sys;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.model.sys.Role;
import com.yunxi.service.localService.sys.RoleService;
import com.yunxi.sys.pojo.RoleVO;
import com.yunxi.sys.service.RoleDubboService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 * @author
 * @since 2019-05-08
 */
public class RoleDubboServiceImpl implements RoleDubboService {

    @Autowired
    @Qualifier(value = "roleServiceImpl")
    RoleService roleService;

    @Override
    public List listByOrgId(String orgId) {
        return roleService.listByOrgId(orgId);
    }

    @Override
    public PageInfo pageByVo(RoleVO roleVO, Integer pageNum, Integer pageSize) {
        return roleService.pageByVo(roleVO,pageNum,pageSize);
    }

    @Override
    public List listByVo(RoleVO roleVO) {
        return roleService.listByVo(roleVO);
    }

    @Override
    public RoleVO getById(String roleId) {
        Role role =  roleService.getById(roleId);
        RoleVO vo = new RoleVO();
        BeanUtils.copyProperties(role,vo);
        return vo;
    }

    @Override
    public void removeByList(List<RoleVO> roleList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        roleService.removeByListVo(roleList);
    }

    @Override
    public void saveOrUpdate(RoleVO role,LoginInfo loginInfo) {
        if (StringUtils.isEmpty(role.getRoleId())){
            role.setRoleId(role.getRoleCode());
        }
        if (StringUtils.isEmpty(role.getTenantId()) ){
            role.setTenantId("pms");
        }
        Role r = new Role();
        BeanUtils.copyProperties(role,r);
        roleService.saveOrUpdate(r);
    }

    @Override
    public RoleVO getByRoleCode(String roleCode) {
        return roleService.getByRoleCode(roleCode);
    }
}
